package org.jypj.dev.vo;

import com.google.gson.Gson;

import java.util.HashMap;
import java.util.Map;

/**
 * 返回安卓接口的对象
 *
 * @author chenyu
 */
public class Result {

    private int code = 0;//状态
    private String msg = "接口调用成功!";//信息
    private String excMsg = "";//异常信息
    private Map<String, Object> dataMap = new HashMap<>();//数据集合

    public int getCode() {
        return code;
    }

    public void setCode(int code) {
        this.code = code;
    }

    public String getExcMsg() {
        return excMsg;
    }

    public void setExcMsg(String excMsg) {
        this.excMsg = excMsg;
    }

    public String getMsg() {
        return msg;
    }

    public void setMsg(String msg) {
        this.msg = msg;
    }

    public Map<String, Object> getDataMap() {
        return dataMap;
    }

    public void setDataMap(Map<String, Object> dataMap) {
        this.dataMap = dataMap;
    }

    /**
     * 设置抛出异常情况的状态
     *
     * @param e
     */
    public void setErrorStatus(Exception e) {
        this.setCode(-1);
        this.setMsg("网络异常");
        this.setExcMsg(e.toString());
    }

    @Override
    public String toString() {
        Gson gson = new Gson();
        return gson.toJson(this);
    }
}
